package com.tomas.demo.common.jsonResult;

import java.io.Serializable;
import java.util.Map;

/**
 * 自定义返回值类型 会被转为JSON
 */
public class ApiResult implements Serializable {
    private String code;
    private String message;
    private Object data;

    public ApiResult() {
    }

    public ApiResult(String code,String message) {
        this.setCode(code);
        this.setMessage(message);
    }
    public ApiResult(String code,String message, Object data) {
        this.setCode(code);
        this.setMessage(message);
        this.setData(data);
    }

    public ApiResult(String code,String message, Map data) {
        this.setCode(code);
        this.setMessage(message);
        this.setData(data);
    }


    public static ApiResult ok() {
        return new ApiResult("200","OK",null);
    }

    public static ApiResult ok(String message) {
        return new ApiResult("200",message,null);
    }

    public static ApiResult ok(String message, Object data) {
        return  new ApiResult("200",message,data);
    }

    public String getCode() {
        return code;
    }
    public ApiResult setCode(String code) {
        this.code = code;
        return this;
    }


    public String getMessage() {
        return this.message;
    }

    public ApiResult setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getData() {
        return this.data;
    }

    public ApiResult setData(Object data) {
        this.data = data;
        return this;
    }
}